﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data.SqlClient;
namespace DAO
{
    class ChiTietHoaDon
    {
        public int ThemHoaDon(ChiTietHoaDonDTO mnDTO)
        {
            SqlConnection conn = DataProvider.sqlconn;
            conn.Open();
            string sql = "INSERT INTO ChiTietHoaDon(MaMonAn, MaBan, MaHD, SoLuong, DonGia, TongTien) VALUES('"+this+"', '"+this+"', '"+this+"', '"+this+"', '"+this+"', '"+this+"')";
            SqlCommand cmd = new SqlCommand(sql, conn);
            cmd.CommandText = sql;
            int kq = cmd.ExecuteNonQuery();
            conn.Close();
            if (kq >= 0)
                return 1;
            else
                return 0;
        }
        public int CapNhatMonAn(int MaMA)
        {
            SqlConnection conn = DataProvider.sqlconn;
            conn.Open();
            string sql = "Update ChiTietHoaDon set MaHD='"+this+"', TenMon='"+this+"', GiaBD='"+this+"', GiaNH='"+this+"', DonVi='"+this+"' where MaMonAn='"+MaMA+"'";
            SqlCommand cmd = new SqlCommand(sql, conn);
            cmd.CommandText = sql;
            int kq = cmd.ExecuteNonQuery();
            conn.Close();
            if (kq >= 0)
                return 1;
            else
                return 0;
        }
        public int XoaMonAn(int MaMA)
        {
            SqlConnection conn = DataProvider.sqlconn;
            conn.Open();
            string sql = "Delete from ChiTietMonAn where MaHD='" + MaMA + "'";
            SqlCommand cmd = new SqlCommand(sql, conn);
            cmd.CommandText = sql;
            int kq = cmd.ExecuteNonQuery();
            conn.Close();
            if (kq >= 0)
                return 1;
            else
                return 0;
        }
        public int LayMa()
        {
            SqlConnection conn = DataProvider.sqlconn;
            conn.Open();
            string sql = "select count* from MonAn";
            SqlCommand cmd = new SqlCommand(sql, conn);
            cmd.CommandText = sql;
            SqlDataAdapter da = new SqlDataAdapter();
            int kq = cmd.ExecuteNonQuery();
            conn.Close();
            return kq;
        }
    }
}
